<template>
    <div class="page matchList">
        <div class="linesPan">
            <div class="logo">
                <div class="icon">
                    <img :src="logoImg" alt="">
                </div>
                <div class="title">{{sysTitle}}</div>
            </div>
            <div class="lines">
                <div @click="onPickLine(-99)" :class="lines.current==-99 ? 'allLines line active':'allLines line'">
                    所有剑道
                </div>
                <div class="lineItems" id="lineItems">
                    <div class="lineList" id="lineList" :style="'height:'+lineHeight+'px'">
                        <el-row :gutter="10">
                            <el-col :span="8"
                                v-for="(line,index) in lines.items"
                                :key="index">
                                <div
                                    :class="lines.current==line.CoureID?'line-item line active':'line-item line'"
                                    @click="onPickLine(line.CoureID)"
                                >
                                    {{line.CoureName}}
                                </div>
                            </el-col>
                        </el-row>
                    </div>
                </div>
            </div>
        </div>

        <div class="matchsPan">
            <div class="matchList" id="matchList">
                <ul class="lstMatchs" :style="'height:'+matchHeight+'px'">
                    <li
                        v-for ="(match,matchIndex) in matchs"
                        :key="matchIndex"
                        @click="goAthList(matchIndex)"
                    >
                        <div class="matchInfo">
                            <div class="matchCode">{{match.DisplayOrder}}</div>
                            <div class="eventName">{{match.EventName}}</div>
                            <div class="phaseName">{{match.PhaseName}}</div>
                            <div class="info">{{match.MatchInfo}}</div>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</template>

<script>
export default {
  mounted () {
    var me = this
    try {
      me.$nextTick().then(_ => {
        me.init()
      })
    } catch (er) {
      console.log(er)
    }
  },
  data () {
    return {
      logoImg: require('../res/imgs/logo.png'),
      sysTitle: '击剑记分器',
      lineHeight: 300,
      matchHeight: 300,
      lines: {
        items: [],
        current: -99
      },
      matchs: []
    }
  },
  methods: {
    init () {
      var me = this
      try {
        me.resize()
        me.getLines().then(_ => {
          me.onPickLine(me.lines.current)
        })
      } catch (er) {
        console.log(er)
      }
    },
    resize () {
      var me = this
      try {
        var h = document.getElementById('lineItems').offsetHeight
        me.lineHeight = h
        h = document.getElementById('matchList').offsetHeight
        me.matchHeight = h
      } catch (er) {
        console.log(er)
      }
    },
    onPickLine (coureId) {
      var me = this
      try {
        me.lines.current = coureId
        me.getMatchs()
      } catch (er) {
        console.log(er)
      }
    },
    goAthList (matchIndex) {
      var me = this
      try {
        var match = me.matchs[matchIndex]
        var ps = {
          matchId: match.MatchID,
          typeCode: ''
        }
        me.$router.push({
          path: 'athList',
          query: match
        })
      } catch (er) {
        console.log(er)
      }
    },
    getLines () {
      var me = this
      return new Promise((success, faild) => {
        try {
          var key = 'fe2023/ts/getLines'
          me.feSys.query(key, {}).then(res => {
            var items = []
            if (res && res != null && res.length > 0) {
              items = res.filter(r => {
                return r.CoureID > 0
              })
            }
            me.lines.items = items
            success()
          })
        } catch (er) {
          console.log(er)
          success()
        }
      })
    },
    getMatchs () {
      var me = this
      return new Promise((success, faild) => {
        try {
          var key = 'fe2023/ts/getMatchs'
          var ps = {
            coureId: me.lines.current
          }
          me.feSys.query(key, ps).then(res => {
            console.log(res)
            var items = []
            if (res && res != null && res.length > 0) {
              items = res
            }
            me.matchs = items
            success()
          })
        } catch (er) {
          console.log(er)
          success()
        }
      })
    }
  }

}
</script>

<style lang="less" scoped>
    @import url('./fe.less');
    .matchList{
        display: flex;
        background-color: #0077fe;
        color: #fff;
        .linesPan{
            width: 300px;
            background-color: #0b4383;
            padding: 10px;
            height: 100%;
            display: flex;
            flex-direction: column;
            .logo{
                display: flex;
                align-items: center;
                border-bottom: 2px solid #0077fe;
                padding-bottom: 10px;
                .icon{
                    height: 40px;
                    padding: 3px;
                    background-color: #fff;
                    border-radius: 2px;
                    img{
                        width: 100%;
                        height: 100%;
                    }
                }
                .title{
                    padding-left: 10px;
                    font-weight: bold;
                    font-size: 1.5em;
                }
            }
            .lines{
                flex: 1;
                padding: 10px 0;
                display: flex;
                flex-direction: column;
                .line {
                    height: 50px;
                    line-height: 50px;
                    text-align: center;
                    background-color: #175aa7;
                }
                .line.active {
                    background-color: #e90f50;
                }

                .allLines {
                    margin-bottom: 10px;
                }

                .lineItems{
                    flex: 1;
                    .lineList{
                        box-sizing: border-box;
                        overflow-x: hidden;
                        overflow-y: auto;
                        .line{
                            margin-bottom: 10px;
                        }

                    }
                }
                .lineList::-webkit-scrollbar{
                    width: 8px;
                    height: 108px;
                }
                .lineList::-webkit-thumb{
                    background-color: rgb(206, 206, 212);
                    border-radius: 10px;
                }

            }
        }

        .matchsPan{
            flex: 1;
            height: 100%;
            padding: 10px;
            .matchList{
                height: 100%;
                ul.lstMatchs{
                    width:100%;
                    font-size: 1.2em;
                    overflow-x: hidden;
                    overflow-y: auto;
                    li{
                        margin-bottom: 5px;
                        background-color: #2483f0;
                        padding: 15px;

                        .matchInfo{
                            display: flex;
                            align-items: center;
                            .matchCode{
                                padding-right: 15px;
                            }
                            .eventName{
                                padding-right: 15px;
                            }
                            .phaseName{
                                padding-right: 15px;
                            }
                        }

                    }
                    li:active{
                        background-color: #0b4383;

                    }
                }
                .lstMatchs::-webkit-scrollbar{
                    width: 8px;
                    height: 108px;
                }
                .lstMatchs::-webkit-thumb{
                    background-color: rgb(206, 206, 212);
                    border-radius: 10px;
                }
            }
        }
    }
</style>
